<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="org.dom4j.*"%>
<%@ page import="org.dom4j.io.*"%>
<%@ page import="org.apache.commons.httpclient.*" %>
<%
	String city = request.getParameter("city");
	String url = "http://www.thinkpage.cn/weather/api.svc/getLocations?query="
			+ city + "&language=zh-chs&format=json&key=";
 
 
	DefaultHttpClient httpClient=new DefaultHttpClient();
	HttpGet httpget=new HttpGet(url);
	ResponseHandler<String> responseHandler=new BasicResponseHandler();
	String responseBody=httpclient.execute(httpget,responseHandler);
	System.out.print(responseBody);
	
	SAXReader reader = new SAXReader();
	Document doc = reader.read(url);
	out.print(doc);
	Element root = doc.getRootElement();
	Element id = root.element("Id");
	Element name = root.element("Name");

	StringBuffer result = new StringBuffer("{");
	result.append("Id:'" + id + "',");
	result.append("Name:'" + name + "'}");
	response.getWriter().write(result.toString());
%>
